package com.util;

public class ByteArrayUtil {
	 public ByteArrayUtil()
	    {
	    }

	    public static byte[] getSubArray(byte src[], int begin, int length)
	    {
	        if(src == null)
	            return null;
	        byte ret[];
	        int l;
	        if(begin + length > src.length)
	        {
	            ret = new byte[src.length - begin];
	            l = src.length;
	        } else
	        {
	            ret = new byte[length];
	            l = length;
	        }
	        for(int i = begin; i < l + begin; i++)
	            ret[i - begin] = src[i];

	        return ret;
	    }

	    public static String byteArrayToHexString(byte b[])
	    {
	        StringBuffer s = new StringBuffer();
	        for(int j = 0; j < b.length; j++)
	        {
	            s.append(Integer.toHexString(b[j] >> 4 & 0xf));
	            s.append(Integer.toHexString(b[j] & 0xf));
	        }

	        return new String(s);
	    }

	 /*   public static String getCurrentDate()
	    {
	        GregorianCalendar gc = new GregorianCalendar();
	        Timestamp ret = new Timestamp(gc.getTime().getTime());
	        return ret.toString();
	    }
*/
	    public static byte[] intToByte(int number)
	    {
	        int temp = number;
	        byte b[] = new byte[4];
	        for(int i = b.length - 1; i > -1; i--)
	        {
	            b[i] = (new Integer(temp & 0xff)).byteValue();
	            temp >>= 8;
	        }

	        return b;
	    }
}
